package com.huaxin.device.dto.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.huaxin.hxenum.base.BaseCodeEnum;

/**
 * 相数枚举
 */
public enum PhaseCount implements BaseCodeEnum<Integer> {

    SINGLE_PHASE(1, "单相"),
    THREE_PHASE(3, "三相");

    @EnumValue
    private final Integer code;
    private final String displayName;

    PhaseCount(Integer code, String displayName) {
        this.code = code;
        this.displayName = displayName;
    }

    @JsonValue
    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getDisplayName() {
        return displayName;
    }

    public static PhaseCount of(Integer code) {
        for (PhaseCount type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        return null;
    }

    public static boolean isValid(Integer code) {
        return of(code) != null;
    }

    /**
     * 支持 int 基本类型调用
     */
    public static boolean isValid(int code) {
        return isValid((Integer) code);
    }
}